package com.kuizii.discovery.config;


import com.kuizii.discovery.client.LiteServiceRegistry;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;


@Configuration
public class BootstrapListener implements ApplicationListener<ApplicationStartedEvent> {

    ServiceRegistry serviceRegistry;
    Registration liteServiceRegistration;

    public BootstrapListener(LiteServiceRegistry registry, Registration liteServiceRegistration) {
        this.serviceRegistry = registry;
        this.liteServiceRegistration = liteServiceRegistration;
    }

    @Override
    public void onApplicationEvent(ApplicationStartedEvent applicationStartedEvent) {

        serviceRegistry.register(liteServiceRegistration);
    }

}
